package com.calsoft.Hops_Mobile_Tablet.card_ui_fragment;
/*
 * User: Minh Diep
 * Date: 6/28/13
 * Time: 11:09 AM
 */


import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.calsoft.Hops_Mobile_Tablet.CardUIDisplayActivity;
import com.calsoft.Hops_Mobile_Tablet.R;
import com.calsoft.Hops_Mobile_Tablet.base.App;
import com.calsoft.Hops_Mobile_Tablet.dummy.Hotel;
import com.calsoft.Hops_Mobile_Tablet.dummy.StaticData;

public class HotelCardUIFragment extends Fragment {


    public HotelCardUIFragment() {
        // Empty constructor required for fragment subclasses
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_card_ui_hotel, container, false);
        getActivity().setTitle(App.APP_TITLE);

        StaticData staticData = new StaticData();
        String itemId = getArguments().getString(CardUIDisplayActivity.CARD_UI_ITEM_ID);
        Hotel hotel = staticData.hotelHashMap.get(itemId);

        TextView titleTv = (TextView) rootView.findViewById(R.id.card_ui_item_title);
        TextView nameTv = (TextView) rootView.findViewById(R.id.card_ui_item_name_tv);
        ImageView mainIv = (ImageView) rootView.findViewById(R.id.card_ui_item_main_iv);
        TextView hotelLocationTv = (TextView) rootView.findViewById(R.id.hotel_location_tv);
        TextView hotelPhoneNumberTv = (TextView) rootView.findViewById(R.id.hotel_phone_number_tv);
        TextView hotelCheckInTv = (TextView) rootView.findViewById(R.id.hotel_check_in_tv);
        TextView hotelCheckOutTv = (TextView) rootView.findViewById(R.id.hotel_check_out_tv);

        Typeface tf = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(),
                "fonts/Roboto-Light.ttf");
        titleTv.setTypeface(tf);
        nameTv.setTypeface(tf);

        mainIv.setImageResource(hotel.getImageId());
        nameTv.setText(hotel.getHotelName());
        hotelLocationTv.setText(hotel.getHotelAddress());
        hotelPhoneNumberTv.setText(hotel.getHotelPhoneNumber());
        hotelCheckInTv.setText(hotel.getCheckInInfo());
        hotelCheckOutTv.setText(hotel.getCheckOutInfo());

        final String phoneNumber = "tel:" + hotel.getHotelPhoneNumber();

        LinearLayout hotelLocationBtn = (LinearLayout) rootView.findViewById(R.id.hotel_location_btn);
        LinearLayout hotelCallBtn = (LinearLayout) rootView.findViewById(R.id.hotel_call_btn);
        hotelLocationBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = "http://maps.google.com/maps?saddr="
                        + "33.851752,-118.287233"
                        + "&daddr=" + "34.137037,-118.358402";
                Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
            }
        });

        hotelCallBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse(phoneNumber));
                startActivity(intent);
            }
        });

        return rootView;
    }
}
